package com.mxl.service.fulfillment.impl;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;

import com.mxl.service.channel.adapter.ChargeService;
import com.mxl.service.dto.ChargeRequest;
import com.mxl.service.dto.ChargeResponse;
import com.mxl.service.dto.FulfillOrderRequest;
import com.mxl.service.exception.NoMatchingMobileException;
import com.mxl.service.fulfillment.OrderFulfillerService;

public class OrderFulfillerServiceImpl implements OrderFulfillerService {

	private ChargeService chargeService;

	public void fulfillOrder(FulfillOrderRequest order)
			throws NoMatchingMobileException {
		// TODO Auto-generated method stub
		// 保存发货订单
		

		// 请求渠道
		ChargeResponse res = chargeService.charge(wrapChargeOrder(order));
		
		//根据结果修改FulfillOrder 的状态  接着修改 paymentorder状态 puchasrorder状态 还有错误码  时间 金额等信息
		
		//记账 通知商户
	}

	private ChargeRequest wrapChargeOrder(FulfillOrderRequest request) {
		ChargeRequest order = new ChargeRequest();
		try {
			BeanUtils.copyProperties(request, order);
			// 设置请求金额
			order.setChargeAmount(request.getRequestAmount());
			// 设置渠道 寻找渠道

			// 设置送往渠道的seqNo (时间年月日 +序列6位)
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return order;
	}

}
